<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{fragments/common :: head}"></head>
<body>
  <div class="portletBody container-fluid">
    <div th:replace="~{fragments/common :: menu('add')}"></div>

    <div th:if="${success}" class="sak-banner-success" role="status" th:text="${success}">Success</div>
    <div th:if="${alert}" class="sak-banner-error" role="alert" th:text="${alert}">Error</div>

    <h1 class="h4 mb-3" th:text="${optionForm.optionId == null} ? #{new_option_title} : #{edit_option_title}">Option</h1>
    <p class="text-muted">
      <span th:text="#{new_poll_question}">Question</span>:
      <span th:utext="${poll.text}">Poll question</span>
    </p>

    <form th:action="@{/pollOption}" th:object="${optionForm}" method="post">
      <input type="hidden" th:field="*{pollId}" />
      <input type="hidden" th:field="*{optionId}" />

      <div class="mb-3">
        <label class="form-label" for="option-text" th:text="#{new_poll_option}">Option</label>
        <textarea id="option-text"
                  class="form-control"
                  th:classappend="${#fields.hasErrors('text')}? ' is-invalid'"
                  rows="4"
                  th:field="*{text}"
                  required></textarea>
        <div class="invalid-feedback" th:if="${#fields.hasErrors('text')}" th:errors="*{text}">Provide text</div>
      </div>

      <div class="act">
        <button type="submit" name="submitAction" value="save" class="active" th:text="#{new_poll_submit}">Save</button>
        <button type="submit" name="submitAction" value="addAnother" class="active" th:text="#{new_poll_saveoption}">Save and add options</button>
        <button type="button" class="active" th:onclick="|location.href='@{/voteAdd(pollId=${poll.id})}'|" th:text="#{new_poll_cancel}">Cancel</button>
      </div>
    </form>
  </div>
</body>
</html>
